#include <stdio.h>
#include <stdlib.h>

///////////////////////小鹏题目-c指定大小容器 ////////////////////////
typedef struct _Container_T {
		int array[5];
		int num;
} Container_T;
bool insertNumberToContainer(int value, Container_T *pCon) {
		bool res = true;

		if (value == 1) {
				if ((pCon->num == 0) || (pCon->num == 5)) {
						pCon->array[0] = 1;
				} else {
						for (int i = 0; i < pCon->num; i++) {
								if (pCon->array[i] == 2) {
										for (int j = pCon->num; j > i; --j) {
												pCon->array[j] = pCon->array[j - 1];
										}
										pCon->array[i] = 1;
										break;
								} else {
										pCon->array[pCon->num] = 1;
								}
						}
				}
				if (pCon->num != 5) {
						++pCon->num;
				}
		} else if (value == 2) {
				if (pCon->num == 0) {
						pCon->array[0] = 2;
				} else if (pCon->num == 5) {
						for (int i = 0; i < pCon->num; ++i) {
								if ((pCon->array[i] == 2) && (i != 0)) {
										pCon->array[i - 1] = 2;
										break;
								}
						}
				} else {
						pCon->array[pCon->num] = 2;
				}
				if (pCon->num != 5) {
						++pCon->num;
				}
		} else {
				res = false;
				printf("输入数字非法,请重新输入");
		}
		return res;
}


int main(){

		Container_T *arr = (Container_T *)calloc(1, sizeof(Container_T));
		int tmp = -1;
		printf("初始数据为:\n");
		for (int i = 0; i < 5; ++i) {
				printf("%d ", arr->array[i]);
		}
		int input_num = 0;
		printf("\n输入预计插入的数据个数\n");
		scanf("%d", &input_num);
		printf("\n输入插入的数据\n");
		while (input_num--) {
				scanf("%d", &tmp);
				bool flag = insertNumberToContainer(tmp, arr);
				if (flag) {
						printf("插入后数据:");
						for (int i = 0; i < 5; ++i) {
								printf("%d ", arr->array[i]);
						}
				}
				printf("\n输入插入的数据\n");
		}
		free(arr);

		return 0;
}